import * as http from 'http';
import app from '../src/app';

let currentApp = app.callback();

// 创建server
const server = http.createServer(currentApp);
server.listen(3000);

// 热加载
if (module.hot) {
  // console.log('reload.');
  // 监听./app.ts
  module.hot.accept('../src/app.ts', () => {
      // 如果有改动，就使用新的app来处理请求
      server.removeListener('request', currentApp);
      currentApp = app.callback();
      server.on('request', currentApp);
  });
}
